package com.yanqu.road.server.cmd.activity.gashapon;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.GashaponProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.gashapon.GashaponModule;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @Author : Cxp
 * @Time : 2024-10-21
 * @Description : 幸运扭蛋-抽扭蛋
 */

@Cmd(code = Protocol.S_GASHAPON_DRAW, desc = "抽扭蛋")
public class GashaponDrawCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GashaponProto.GashaponDrawReq req = GashaponProto.GashaponDrawReq.parseFrom(packet.getBytes());
        ret = player.getModule(GashaponModule.class).draw(req.getActivityId(), req.getType());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GashaponProto.GashaponDrawResp.Builder builder = GashaponProto.GashaponDrawResp.newBuilder();
            builder.setRet(ret);
            builder.setReward("");
            GashaponModule module = player.getModule(GashaponModule.class);
            builder.setUserData(module.buildRet(module.getUserData()));
            player.sendPacket(Protocol.U_GASHAPON_DRAW, builder);
        }
    }
}
